package wsi.depend.assist;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import wsi.function.Function;

public class AssistantManager {

	private static AssistantManager shared;

	public static AssistantManager shared() {
		if (shared == null)
			shared = new AssistantManager();

		return shared;
	}

	private final List<Assistant> assistants = new ArrayList<>();
	private final Set<Function> scheduledFunctions = new HashSet<>();

	private AssistantManager() {

	}

	public void add(Assistant e) {
		assistants.add(e);
		schedule(e.getProvider());
	}

	public Assistant assist(Function f) {
		for (Assistant a : assistants)
			if (a.getProvider() == f)
				return a;

		return null;
	}

	public void schedule(Function f) {
		scheduledFunctions.add(f);
	}

	public boolean scheduled(Function f) {
		return scheduledFunctions.contains(f);
	}
}
